load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
load("//tools:defaults.bzl", "jasmine_node_test", "ts_library")

package(default_visibility = ["//visibility:public"])

ts_library(
    name = "transform-markdown",
    srcs = glob(
        ["**/*.ts"],
        exclude = [
            "*.spec.ts",
        ],
    ),
    # TODO(ESM): remove this once the Bazel NodeJS rules can handle ESM with `nodejs_binary`.
    devmode_module = "commonjs",
    tsconfig = ":tsconfig.json",
    deps = [
        "//tools/highlight-files:sources",
        "@npm//@types/marked",
        "@npm//@types/node",
        "@npm//marked",
    ],
)

nodejs_binary(
    name = "markdown-to-html",
    data = [
        ":transform-markdown",
        "@npm//highlight.js",
        "@npm//marked",
    ],
    entry_point = ":transform-markdown.ts",
    templated_args = ["--bazel_patch_module_resolver"],
)

ts_library(
    name = "unit_test_lib",
    testonly = True,
    srcs = glob(
        ["*.spec.ts"],
    ),
    tsconfig = ":tsconfig.json",
    visibility = ["//visibility:private"],
    deps = [
        ":transform-markdown",
        "@npm//@types/jasmine",
        "@npm//@types/node",
        "@npm//marked",
        "@npm//typescript",
    ],
)

jasmine_node_test(
    name = "unit_tests",
    srcs = [":unit_test_lib"],
    visibility = ["//visibility:private"],
)
